//
//  IdleFishRequest.swift
//  IdleFishRequest
//
//  Created by Ben on 2021/9/9.
//

import Foundation

protocol IdlefishRequest {
    
    func fetchGoodsCategoryList(superId: Int) async throws -> [HomeRecommendGoodsCategoryModel]
    
    func fetchUserChannelList(userId: Int) async throws -> [HomeRecommendGoodsCategoryModel]
    
    func updateUserChannelList(userId: Int, channel_ids: String) async throws -> NetworkNilModel
    
    
    func fetchCurrLocationGoodsCategoryList(cityName: String) async throws -> [HomeRecommendGoodsCategoryModel]

}

extension IdlefishRequest {
    
    func fetchGoodsCategoryList(superId: Int) async throws -> [HomeRecommendGoodsCategoryModel] {
        let result = try await NetworkTool.awaitRequest(request: API.goods_category_list(super_id: superId), responseType: [HomeRecommendGoodsCategoryModel].self)
        
        return result.data ?? []
    }
    
    func fetchUserChannelList(userId: Int) async throws -> [HomeRecommendGoodsCategoryModel] {
        
        let result = try await NetworkTool.awaitRequest(request: API.user_channel_list(user_id: userId), responseType: [HomeRecommendGoodsCategoryModel].self)
        
        return result.data ?? []
    }
    
    func updateUserChannelList(userId: Int, channel_ids: String) async throws -> NetworkNilModel {
        
        let result = try await NetworkTool.awaitRequest(request: API.update_user_channel_list(user_id: userId, channel_ids: channel_ids), responseType: NetworkNilModel.self)
        
        return result.data ?? NetworkNilModel()
    }
    
    func fetchCurrLocationGoodsCategoryList(cityName: String) async throws -> [HomeRecommendGoodsCategoryModel] {
        let result = try await NetworkTool.awaitRequest(request: API.curr_location_category_list(city_name: cityName), responseType: [HomeRecommendGoodsCategoryModel].self)
        
        return result.data ?? []
    }
    
}
